import QtQuick 2.0
import QtQuick.Controls 2.12
import "../components"
Item {
    id: root

    property bool mutexCheckBox: false


    function refresh(){
        chart_bar.refresh()
        chart_line.refresh()
    }

    function initCheckBox(){
        mutexCheckBox = true
        checkFAM.check = true
        checkCY5.check = true
        checkVIC.check = true
        checkROX.check = true
        mutexCheckBox = false
    }

    function updateCheckbox(){

        if(mutexCheckBox){
            return
        }

        accessFilter = []
        if(checkFAM.getStatus()){
            accessFilter.push(["FAM"])
        }if(checkROX.getStatus()){
            accessFilter.push(["ROX"])
        }if(checkVIC.getStatus()){
            accessFilter.push(["VIC"])
        }if(checkCY5.getStatus()){
            accessFilter.push(["CY5"])
        }
        updateRunningChart()

    }

    signal fullScreen()

    x: 0
    y: 0
    height: parent.height
    width: parent.width
    Rectangle{   // 按钮控制切换
        id: layout_tab
        height: 40*dp
        width: root.width
        PushButton{
            id: buttonBarChart
            title: "实时图谱"
            width: 80*dp
            height: 40*dp
            x: 20*dp
            underlineSelect: true
            isSelected: currentPage === 0
            onReleased: {
                currentPage = 0
                chart_bar.refresh()
            }
        }PushButton{
            id: buttonLineChart
            title: "曲线图谱"
            width: 80*dp
            height: 40*dp
            x: 120*dp
            underlineSelect: true
            isSelected: currentPage === 1
            onReleased: {
                currentPage = 1
            }
        }
        PushButton{
            title: "筛选"
            x: parent.width - 180*dp
            y: 55*dp
            height: 35*dp
            defaultMode2: true
            onReleased: {
                boxFilterRunning.show()
            }
        }

        PushButton{
            title: isFullScreen ?  " 取消全屏" : " 全屏"
            width: 120*dp
            x: parent.width-150*dp
            y: -3
            button_icon: isFullScreen ? "qrc:/picture/fullscreen_off.png" : "qrc:/picture/fullscreen_on.png"
            onReleased: {
                root.fullScreen()
                if(isFullScreen){
                    root.x = root.x+1
                }else{
                    root.x = root.x-1
                }
                console.log("全屏显示")
            }
//            visible: false // 全屏功能暂时不好使
        }

        CustomBorder{
            bBorderwidth: 1
            borderColor: "#CCCCCC"
        }

    }
    Item{   // CheckBox
        id: layout_checkbox
        height: 60*dp
        width: root.width
        y: 40*dp
        Row{
            anchors.centerIn: parent
            CustomCheckBox{
                id: checkFAM
                box_text: "FAM"
                fontColor: config.colorChannel1
                check: true
                onCheckChanged: {
                    updateCheckbox()
                }
            }CustomCheckBox{
                id: checkVIC
                box_text: "VIC"
                fontColor: config.colorChannel2
                check: true
                onCheckChanged: {
                    updateCheckbox()
                }
            }CustomCheckBox{
                id: checkROX
                box_text: "ROX"
                fontColor: config.colorChannel3
                check: true
                onCheckChanged: {
                    updateCheckbox()
                }
            }CustomCheckBox{
                id: checkCY5
                box_text: "CY5"
                fontColor: config.colorChannel4
                check: true
                onCheckChanged: {
                    updateCheckbox()
                }
            }
        }

    }
    Rectangle{
        id: layout_graph
        clip: true
        visible: isCollect
        height: root.height-100*dp
        width: root.width
        y: 100*dp
        RunningChartBar{
               id: chart_bar
               anchors.fill: parent
               visible: currentPage === 0
        }
        RunningChartLine{
               id: chart_line
               anchors.fill: parent
               visible: currentPage === 1
        }
    }
    Rectangle{
        id: noRunningGraph
        visible: ! isCollect
        height: root.height-120*dp
        width: root.width-20*dp
        y: 110*dp
        x: 10*dp
        Image{
            width: 220*dp
            height: 180*dp
            anchors.centerIn: parent
            anchors.verticalCenterOffset: -30*dp
            source: "qrc:/picture/empty2.png"
            Text{
//                text: "当前实验未采集荧光数据"
                text: ""
                font.pixelSize: config.fontsize
                anchors.horizontalCenter: parent.horizontalCenter
                y: 195*dp
                color: "#AAAAAA"
            }
        }
    }
}
